package com.bookstore.service.impl;

import com.bookstore.domain.Order;
import com.bookstore.mapper.OrderMapper;
import com.bookstore.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Order> findAll(Integer isPay, Integer isDeliver, String username, Integer uid) {
        return orderMapper.findAll(isPay, isDeliver, username, uid);
    }

    @Override
    public Integer upDeliver(String orderId, Integer isDeliver) {
        return orderMapper.upDeliver(orderId, isDeliver);
    }

    @Override
    public int upRefund(String orderId, int i) {
        return orderMapper.upRefund(orderId, i);
    }

    @Override
    public List<Order> findAllByUid(Integer isPay, Integer isDeliver, Integer buyers, String username) {
        return orderMapper.findByUid(isPay, isDeliver, buyers, username);
    }

    @Override
    public int Pay(String orderId) {
        return orderMapper.upPay(orderId);
    }

    @Override
    public int receipt(String orderId) {
        return orderMapper.upReceipt(orderId);
    }

    @Override
    public int refund(String orderId) {
        return orderMapper.userUpRefund(orderId);
    }

    @Override
    public Order findOneByOrderId(String orderId) {
        return orderMapper.findOneByOrderId(orderId);
    }

    @Override
    public int upOrder(Order order) {
        return orderMapper.upOrder(order);
    }

    @Override
    public int delOrder(String orderId, Integer buyersId) {
        /*int result = 0;
        int result1 = 0;
        result = orderMapper.delOrderDetailsByOrderId(orderId);
        result1 = orderMapper.delOrderByOrderIdAndBuyers(orderId, buyersId);
        if(result == result1 && result ==1){
            return 1;
        }*/
        return orderMapper.delOrderByOrderIdAndBuyers(orderId, buyersId);
    }

    @Override
    public int PayToShopping(Order o) {
        return orderMapper.Pay(o);
    }
}
